import { Component, AfterViewInit, ViewChild, NgZone } from "@angular/core";
import { parse } from "gift-pegjs";
import { IndexService } from "./service/utils/index.service";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.less"]
})
export class AppComponent implements AfterViewInit {
  @ViewChild("node", { static: false }) node;
  title = "examPer";
  isShow = false;
  childNode: any;
  textarea = `
    How do you write the word for the number 1? {One}
  `;
  content = "";
  constructor(private utils: IndexService, private zone: NgZone) {}
  ngAfterViewInit() {
    this.formatter(this.textarea);
  }

  formatter(value) {
    const result = parse(value);
    const treeNode = this.node.nativeElement;
    console.log(result);
    this.utils.giftFormat(result, treeNode).then(res => {
      this.childNode = res;
    });
  }
  Change() {
    this.formatter(this.textarea);
    this.textarea = "";
    this.childNode = "";
  }
  rightSwer() {
    this.isShow = !this.isShow;
  }
}
